import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { User } from '@/types/user'
// 用户数据
export const useUserStore = defineStore(
  'cp-user',
  () => {
    // 定义数据
    const user = ref<User>()
    // 定义修改数据的方法
    const setUser = (newUser: User) => {
      user.value = newUser
    }

    // 清空用户，退出后使用
    const delUser = () => {
      user.value = undefined
    }
    return { user, setUser, delUser }
  },
  {
    persist: true
  }
)
